package cat.joronya.supermanager.service;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Hashtable;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.util.Log;
import cat.joronya.supermanager.Supermanager;
import cat.joronya.supermanager.market.Player;
import cat.joronya.supermanager.team.Team;

/**
 * Recuperem el detall de my team. Tambe permet fer operacions
 * referents al meu equip: changes reset, sell, buy and cancel.
 * 
 * @author pol
 */
public class MyTeamDetailSync extends Object 
{
	private static final String TAG = "supermanager";
	
	// el service
	private SupermanagerService service;
	
	// el client http on fer les peticions
	private DefaultHttpClient client = null;
	
	// status de retorn
	public int status = -1;
	
	// team detail
	private static final String TEAM_DETAIL_GET = InitSync.BASE_URL+"/verequipo.php";
	
	// day matches GET
	private static final String DAYMATCHES_GET = "http://www.acb.com/resulcla.php?codigo=LACB-58&jornada=1&resultados=";

	// reset changes
	private static final String TEAM_RESET_CHANGES_POST = InitSync.BASE_URL+"/reset.php";
	
	// sell player
	private static final String TEAM_SELL_PLAYER_GET = InitSync.BASE_URL+"/venta.php";

	// cancel change
	private static final String TEAM_CANCEL_CHANGE_GET = InitSync.BASE_URL+"/reset1.php";
	
	// comprar changes
	private static final String TEAM_BUY_POST = InitSync.BASE_URL+"/mercado.php";

	// dades extretes de les pagina detall
	public Team team;
	
	// hash per guardar team vs team
	protected Hashtable<String, String> dayMatches = null;

	// jornada passada de loginSyn pq no es a les pagines de market
	private Integer jornada = null;
	
	/**
	 * Constructor amb el intentService que el crida.
	 * @param intentService
	 */
	public MyTeamDetailSync(SupermanagerService service, DefaultHttpClient client, Integer jornada)
	{
		this.service = service;
		this.client = client;
		this.jornada = jornada;
	}

	// passem els partits de la setmana previament processats
	public void setDayMatches(Hashtable<String, String> dayMatches)
	{
		this.dayMatches = dayMatches;
	}
	
	/**
	 * Sync the team identified by the idequ passed.
	 * @param idequ
	 */
	public void syncTeam(String idequ)
	{
		try
		{
			// checkejem per connectivitat
			ConnectivityManager cm = (ConnectivityManager) service.getSystemService(Context.CONNECTIVITY_SERVICE);
			boolean online = cm.getActiveNetworkInfo().isConnectedOrConnecting();
			
			if( !online )
				throw new ConnectivityException();
			
			// parsejem el detall
			executeTeamDetailSync(idequ);
			
			// persistim l'equip parsejat
			persist(); 
		}
		catch(ConnectivityException ce){
			// error de connectivitat
			status = Supermanager.CONNECTIVITY_ERROR_STATUS;
	        Log.d(TAG, "MArketSync status: CONNECTIVITY_ERROR_STATUS - "+status);
			return;
		}
		catch(Exception e){
			// altre error, notifiquem i anem offline
			status = Supermanager.OTHER_ERROR_STATUS;
	        Log.d(TAG, "MArketSync status: OTHER_ERROR_STATUS - "+status);
			return;
		}
	}
	
	public void executeTeamDetailSync(String idequ) throws Exception
	{
			HttpGet plHttpGet = new HttpGet(TEAM_DETAIL_GET+"?id_equ="+idequ);
			HttpResponse response = client.execute(plHttpGet);
			ByteArrayOutputStream os = new ByteArrayOutputStream();
	        response.getEntity().writeTo(os);
	        String teamPage = os.toString(HTTP.ISO_8859_1);
	        
	        //MyTeamDetailParser parser = MyTeamDetailParserProvider.getImpl(Package.getPackage("cat.joronya.supermanager.service.htmlcleanerImpl"));
	        MyTeamDetailParser parser = MyTeamDetailParserProvider.getImpl(Package.getPackage("cat.joronya.supermanager.service.substrImpl"));
	        
	        Log.d(Supermanager.TAG, "Start parsing my teams page...");
			long elapsedTime = parser.parse(idequ, teamPage);
			Log.d(Supermanager.TAG, "Stop parsing my teams page! Elapsed time: "+elapsedTime/1000);
			
			// recuperem team parsejat
			team = parser.getTeam();
	        
	        /*MyTeamDetailParser myTeamDetailParser = new MyTeamDetailParser();
	        team = myTeamDetailParser.parse(idequ, teamPage);*/
	        
    		// status p.d. normal
			int teamStatus = Supermanager.MyTeam.STATUS_NORMAL;
			// num. jugadors, p.d. zero
			int numJug = 0;
			
	        // mente equip sense jugadors, calculs
	    	if( team.getPlayers() != null )
	    	{
    			// guardem els jugadors
	    		for(Player player: team.getPlayers().values())
	    		{
	    			// calculem el num. jugadors
	    			if( player.getCodi() != null )
	    				numJug++;
	    			else
	    				teamStatus = Supermanager.MyTeam.STATUS_INCOMPLETE_TEAM;
	    			
	    			// si ja teniem una fitxa lliure l'estat sera incomplet
	    			if( teamStatus == Supermanager.MyTeam.STATUS_INCOMPLETE_TEAM )
	    				continue;

	    			// esta lesionat?
	    			if( "lesio.png".equals(player.getStatus()) )
	    				teamStatus = Supermanager.MyTeam.STATUS_LESIONAT;
	    			// esta descartat?
	    			if( "baixa.png".equals(player.getStatus()) )
	    				teamStatus = Supermanager.MyTeam.STATUS_DESCARTAT;
		    	}
	    	}
	    	
	    	//set team status and numJugadors
	    	team.setStatus(teamStatus);
	    	team.setTeamPlayers(numJug);
	        
			// parsejat ok
	        status = Supermanager.MY_TEAM_DETAIL_PARSED_OK;
	        Log.d(TAG, "MyTeamDetailSync status: MY_TEAM_DETAIL_PARSED_OK - "+status);
	        return;
    }
	
	/**
	 * Reset changes and sync the team identified by the idequ passed.
	 * @param idequ
	 */
	public void resetChanges(String idequ)
	{
		try
		{
			// checkejem per connectivitat
			ConnectivityManager cm = (ConnectivityManager) service.getSystemService(Context.CONNECTIVITY_SERVICE);
			boolean online = cm.getActiveNetworkInfo().isConnectedOrConnecting();
			
			if( !online )
				throw new ConnectivityException();
			
			HttpPost httpPost = new HttpPost(TEAM_RESET_CHANGES_POST);
	        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
	        nameValuePairs.add(new BasicNameValuePair("id_equ",idequ));
	        nameValuePairs.add(new BasicNameValuePair("control", "1"));
	        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			
	        //HttpResponse response = client.execute(httpPost);
	        client.execute(httpPost);
			//ByteArrayOutputStream os = new ByteArrayOutputStream();
	        //response.getEntity().writeTo(os);
	        //String resetPage = os.toString(HTTP.ISO_8859_1);

	        //TODO: revisar q el reset torna la pagina q toca
	        //Log.d(TAG, "reset:\n"+resetPage+"\n");
	        status = Supermanager.MY_TEAM_DETAIL_RESET_CHANGES_OK;
	        
	        Log.d(TAG, "MyTeamDetailSync status: MY_TEAM_DETAIL_RESET_CHANGES_OK - "+status);
		}
		catch(ConnectivityException ce){
			// error de connectivitat
			status = Supermanager.CONNECTIVITY_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: CONNECTIVITY_ERROR_STATUS - "+status);
			return;
		}
		catch(Exception e){
			// altre error, notifiquem i anem offline
			status = Supermanager.OTHER_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: OTHER_ERROR_STATUS - "+status);
			return;
		}
		
		// si no hi ha error, parsejem de nou el team detail
		syncTeam(idequ);
		status = Supermanager.MY_TEAM_DETAIL_RESET_CHANGES_OK;
	}

	/**
	 * Sell player and sync the team identified by the idequ and position passed.
	 * @param idequ
	 */
	public void sellPlayer(String idequ, String position)
	{
		try
		{
			// checkejem per connectivitat
			ConnectivityManager cm = (ConnectivityManager) service.getSystemService(Context.CONNECTIVITY_SERVICE);
			boolean online = cm.getActiveNetworkInfo().isConnectedOrConnecting();
			
			if( !online )
				throw new ConnectivityException();
			
			HttpGet httpGet = new HttpGet(TEAM_SELL_PLAYER_GET+"?id_equ="+idequ+"&posicion="+position);
	        //HttpResponse response = client.execute(httpGet);
	        client.execute(httpGet);
			//ByteArrayOutputStream os = new ByteArrayOutputStream();
	        //response.getEntity().writeTo(os);
	        //String sellPage = os.toString(HTTP.ISO_8859_1);

	        //TODO: revisar q el reset torna la pagina q toca
	        //Log.d(TAG, "sell:\n"+sellPage+"\n");
	        status = Supermanager.MY_TEAM_DETAIL_SELL_OK;
	        
	        Log.d(TAG, "MyTeamDetailSync status: MY_TEAM_DETAIL_SELL_OK - "+status);
		}
		catch(ConnectivityException ce){
			// error de connectivitat
			status = Supermanager.CONNECTIVITY_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: CONNECTIVITY_ERROR_STATUS - "+status);
			return;
		}
		catch(Exception e){
			// altre error, notifiquem i anem offline
			status = Supermanager.OTHER_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: OTHER_ERROR_STATUS - "+status);
			return;
		}
		
		// si no hi ha error, parsejem de nou el team detail
		syncTeam(idequ);
		status = Supermanager.MY_TEAM_DETAIL_SELL_OK;
	}
	
	/**
	 * Cancel player change and sync the team identified by the idequ and position passed.
	 * @param idequ
	 */
	public void cancelChange(String idequ, String position)
	{
		try
		{
			// checkejem per connectivitat
			ConnectivityManager cm = (ConnectivityManager) service.getSystemService(Context.CONNECTIVITY_SERVICE);
			boolean online = cm.getActiveNetworkInfo().isConnectedOrConnecting();
			
			if( !online )
				throw new ConnectivityException();
			
			HttpPost httpPost = new HttpPost(TEAM_CANCEL_CHANGE_GET);
	        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
	        nameValuePairs.add(new BasicNameValuePair("id_equ",idequ));
	        nameValuePairs.add(new BasicNameValuePair("posicion",position));
	        nameValuePairs.add(new BasicNameValuePair("control", "1"));
	        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
			
	        //HttpResponse response = client.execute(httpPost);
	        client.execute(httpPost);
			//ByteArrayOutputStream os = new ByteArrayOutputStream();
	        //response.getEntity().writeTo(os);
	        //String cancelPage = os.toString(HTTP.ISO_8859_1);

	        //TODO: revisar q el reset torna la pagina q toca
	        //Log.d(TAG, "cancel:\n"+cancelPage+"\n");
	        status = Supermanager.MY_TEAM_DETAIL_CANCEL_OK;
	        
	        Log.d(TAG, "MyTeamDetailSync status: MY_TEAM_DETAIL_CANCEL_OK - "+status);
		}
		catch(ConnectivityException ce){
			// error de connectivitat
			status = Supermanager.CONNECTIVITY_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: CONNECTIVITY_ERROR_STATUS - "+status);
			return;
		}
		catch(Exception e){
			// altre error, notifiquem i anem offline
			status = Supermanager.OTHER_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: OTHER_ERROR_STATUS - "+status);
			return;
		}
		
		// si no hi ha error, parsejem de nou el team detail
		syncTeam(idequ);
		status = Supermanager.MY_TEAM_DETAIL_CANCEL_OK;
	}

	/**
	 * Buy player and sync the team identified by the idequ and position passed.
	 * @param idequ
	 */
	public void buyPlayer(String idequ, String position, String idjug)
	{
		try
		{
			// checkejem per connectivitat
			ConnectivityManager cm = (ConnectivityManager) service.getSystemService(Context.CONNECTIVITY_SERVICE);
			boolean online = cm.getActiveNetworkInfo().isConnectedOrConnecting();
			
			if( !online )
				throw new ConnectivityException();
			
			HttpPost httpPost = new HttpPost(TEAM_BUY_POST);
	        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
	        nameValuePairs.add(new BasicNameValuePair("id_equ",idequ));
	        nameValuePairs.add(new BasicNameValuePair("posicion",position));
	        nameValuePairs.add(new BasicNameValuePair("id_jug",idjug));
	        nameValuePairs.add(new BasicNameValuePair("control", "1"));
	        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
		
	        //HttpResponse response = client.execute(httpPost);
	        client.execute(httpPost);
			//ByteArrayOutputStream os = new ByteArrayOutputStream();
	        //response.getEntity().writeTo(os);
	        //String buyPage = os.toString(HTTP.ISO_8859_1);

	        //TODO: revisar q el reset torna la pagina q toca
	        //Log.d(TAG, "buy:\n"+buyPage+"\n");
	        status = Supermanager.MY_TEAM_DETAIL_BUY_OK;
	        
	        Log.d(TAG, "MyTeamDetailSync status: MY_TEAM_DETAIL_BUY_OK - "+status);
		}
		catch(ConnectivityException ce){
			// error de connectivitat
			status = Supermanager.CONNECTIVITY_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: CONNECTIVITY_ERROR_STATUS - "+status);
			return;
		}
		catch(Exception e){
			// altre error, notifiquem i anem offline
			status = Supermanager.OTHER_ERROR_STATUS;
	        Log.d(TAG, "MyTeamDetailSync status: OTHER_ERROR_STATUS - "+status);
			return;
		}
		
		// si no hi ha error, parsejem de nou el team detail
		syncTeam(idequ);
		status = Supermanager.MY_TEAM_DETAIL_BUY_OK;
	}
	
	/**
	 * Guardar les dades trobades a DB.
	 */
    public void persist() 
    {
    	// tractem cada team del llistat
    	Log.d(TAG,"Team["+team.getIdEqu()+"] parsed, going to insert/update");
    	
    	// tractem el detailTeam, guardem dades de pagina interior
    	// hi ha dades del MyTeam i dades del MyTeamDetail (players)

    	// guardar dades de header equip, tant de day com del yourWeekDay
    	insertOrUpdateTeamDetailDay(Supermanager.MyTeam.CONTENT_URI, team);
    	
    	// equip sense jugadors
    	if( team.getPlayers() == null )
    	{
    		Log.d(TAG,"Team ["+team.getIdEqu()+"] has no players");
    		return;
    	}
    		
    	// guardem els jugadors
    	for(Player player: team.getPlayers().values())
    	{
    		// insert or update team player
    		insertOrUpdateMyTeamPlayer(team.getIdEqu(), team.getDay().toString(), player);
    	}
    }

    /**
	 * Insert or Update Team as needed, but just information from detail page
	 * relative to day.
	 * @param uri
	 * @param pl
	 * @return
	 */
	private String insertOrUpdateTeamDetailDay(Uri uri, Team team)
	{
		// insertem al team les dades amb day = day
		ContentValues values = new ContentValues();
		values.put(Supermanager.MyTeam.ID_EQU, team.getIdEqu());
		values.put(Supermanager.MyTeam.DAY, team.getDay());
		values.put(Supermanager.MyTeam.NAME, team.getName());
		values.put(Supermanager.MyTeam.CASH, team.getCash());
		values.put(Supermanager.MyTeam.CANCEL_CHANGES, team.getCancelChanges());
		values.put(Supermanager.MyTeam.CHANGES_DONE, team.getChangesDone());
		values.put(Supermanager.MyTeam.CHANGES_TOTAL, team.getChangesTotal());
		values.put(Supermanager.MyTeam.TEAM_PLAYERS, team.getTeamPlayers());
		values.put(Supermanager.MyTeam.STATUS, team.getStatus());
		
		Uri teamUri = Supermanager.MyTeam.CONTENT_URI;
		String lastPathSegment = "0";
		
		// si update no retorna 1 reg, llavors insert
		if( service.getContentResolver().update(Supermanager.MyTeam.CONTENT_URI, 
				values, 
				Supermanager.MyTeam.ID_EQU+" = ? AND "+
				Supermanager.MyTeam.DAY+" = ? ", 
				new String[]{team.getIdEqu(), team.getDay().toString()}) == 0 )
		{
			teamUri = service.getContentResolver().insert(Supermanager.MyTeam.CONTENT_URI, values);
			lastPathSegment = teamUri.getLastPathSegment();
			Log.d(TAG, "Inserting team detail day data [" + team.getName()
					+ "] with Uri [" + teamUri + "] lastPathSegment ["
					+ lastPathSegment + "] with status: " + team.getStatus()
					+ " and teamPlayers: " + team.getTeamPlayers());
		}
		else
		{
			Cursor cursor = service.getContentResolver().
				query(Supermanager.MyTeam.CONTENT_URI, 
					  Supermanager.MyTeam.PROJECTION, 
					  Supermanager.MyTeam.ID_EQU+" = ? AND "+
					  Supermanager.MyTeam.DAY+" = ? ", 
					  new String[]{team.getIdEqu(), team.getDay().toString()}, 
					  Supermanager.MyTeam.DEFAULT_SORT_ORDER);
			
			if( cursor.moveToFirst() )
			{
				lastPathSegment = ""+cursor.getLong(0);
				teamUri = ContentUris.withAppendedId(Supermanager.MyTeam.CONTENT_URI, cursor.getLong(0));
			}
			Log.d(TAG, "Updating team detail day data [" + team.getName()
					+ "] with Uri [" + teamUri + "] lastPathSegment ["
					+ lastPathSegment + "] with status: " + team.getStatus()
					+ " and teamPlayers: " + team.getTeamPlayers());
		}
		
		return lastPathSegment;
	}

	/**
	 * Insert or update MyTeamDetail, players info, as needed.
	 * @param idEqu
	 * @param day
	 * @param player
	 * @return
	 */
	public Uri insertOrUpdateMyTeamPlayer(String idEqu, String day, Player player)
	{
		// setejem el vs_team parsejat per la jornada, si tenim team
		if( player.getTeam() != null )
			player.setVsTeam(this.dayMatches.get(player.getTeam()));
		
		// insertem el team
		ContentValues vplayer = new ContentValues();
		vplayer.put(Supermanager.MyTeamDetail.ID_EQU, idEqu);
		vplayer.put(Supermanager.MyTeamDetail.DAY, day);
		vplayer.put(Supermanager.MyTeamDetail.POSITION, player.getTeamPosition());
		vplayer.put(Supermanager.MyTeamDetail.NUM_POSITION, player.getPosition());
		vplayer.put(Supermanager.MyTeamDetail.BUY, player.isBuy()?1:0);
		vplayer.put(Supermanager.MyTeamDetail.SELL, player.isSell()?1:0);
		vplayer.put(Supermanager.MyTeamDetail.CANCEL, player.isCancel()?1:0);
		vplayer.put(Supermanager.MyTeamDetail.CHANGE, player.isChange()?1:0);
		vplayer.put(Supermanager.MyTeamDetail.CODI_PLAYER, player.getCodi());
		vplayer.put(Supermanager.MyTeamDetail.COST, player.getCost());
		vplayer.put(Supermanager.MyTeamDetail.SIGNING_DAY, player.getBuyDay());
		vplayer.put(Supermanager.MyTeamDetail.PRICE, player.getPrice());
		vplayer.put(Supermanager.MyTeamDetail.WIN, player.isVictory()?1:0);
		vplayer.put(Supermanager.MyTeamDetail.RATING, player.getRating());
		vplayer.put(Supermanager.MyTeamDetail.POINTS, player.getPoints());
		vplayer.put(Supermanager.MyTeamDetail.REBOUNDS, player.getRebounds());
		vplayer.put(Supermanager.MyTeamDetail.THREE, player.getThree());
		vplayer.put(Supermanager.MyTeamDetail.ASSISTS, player.getAssistences());
		vplayer.put(Supermanager.MyTeamDetail.RATING_AVERAGE, player.getAverageRating());
		vplayer.put(Supermanager.MyTeamDetail.POINTS_AVERAGE, player.getAveragePoints());
		vplayer.put(Supermanager.MyTeamDetail.REBOUNDS_AVERAGE, player.getAverageRebounds());
		vplayer.put(Supermanager.MyTeamDetail.THREE_AVERAGE, player.getAverageThree());
		vplayer.put(Supermanager.MyTeamDetail.ASSISTS_AVERAGE, player.getAverageAssistences());
		vplayer.put(Supermanager.MyTeamDetail.STATUS, player.getStatus());
		vplayer.put(Supermanager.MyTeamDetail.NACIONALITY, player.getNacionality());
		vplayer.put(Supermanager.MyTeamDetail.NAME, (player.getName() == null)?"":player.getName());
		vplayer.put(Supermanager.MyTeamDetail.TEAM, (player.getTeam() == null)?"":player.getTeam());
		vplayer.put(Supermanager.MyTeamDetail.VS_TEAM, player.getVsTeam());
		vplayer.put(Supermanager.MyTeamDetail.INFO, player.getInfo());
		
		Uri pUri = Supermanager.MyTeamDetail.CONTENT_URI;
		// si update no retorna 1 reg, llavors insert
		if( service.getContentResolver().update(Supermanager.MyTeamDetail.CONTENT_URI, 
				vplayer, 
				Supermanager.MyTeamDetail.ID_EQU+" = ? AND "+
				Supermanager.MyTeamDetail.DAY+" = ? AND "+
				Supermanager.MyTeamDetail.POSITION+" = ? ", 
				new String[]{ idEqu, day, player.getTeamPosition() }) == 0 )
		{
			pUri = service.getContentResolver().insert(
					Supermanager.MyTeamDetail.CONTENT_URI, vplayer);
			Log.d(TAG, "Inserting player["+ player.getTeamPosition() +"] cod[" + player.getCodi() + "] of team ["
					+ idEqu + "] with Uri [" + pUri + "] "
					+ " buy: "+(player.isBuy()?"1":"0")
					+ " sell: "+(player.isSell()?"1":"0")
					+ " cancel: "+(player.isCancel()?"1":"0")
					+ " change: "+(player.isChange()?"1":"0"));
		}
		else
		{
			Cursor cursor = service.getContentResolver().
			query(Supermanager.MyTeamDetail.CONTENT_URI, 
				  Supermanager.MyTeamDetail.PROJECTION, 
				  Supermanager.MyTeamDetail.ID_EQU+" = ? AND "+
				  Supermanager.MyTeamDetail.DAY+" = ? AND "+
				  Supermanager.MyTeamDetail.POSITION+" = ? ", 
				  new String[]{ idEqu, day, player.getTeamPosition() }, 
				  Supermanager.MyTeamDetail.DEFAULT_SORT_ORDER);
		
			if( cursor.moveToFirst() )
			{
				pUri = ContentUris.withAppendedId(Supermanager.MyTeamDetail.CONTENT_URI, cursor.getLong(0));
		
				Log.d(TAG, "Updating player["+ player.getTeamPosition() +"] cod[" + player.getCodi() + "] of team ["
						+ idEqu + "] with Uri [" + pUri + "]"
						+ " buy: "+(player.isBuy()?"0":"1")
						+ " sell: "+(player.isSell()?"0":"1")
						+ " cancel: "+(player.isCancel()?"0":"1")
						+ " change: "+(player.isChange()?"1":"0"));
			}
		}
		return pUri;
	}
}
